export default {
  namespaced:true,
  //数据节点
  state: () => ({
    address:JSON.parse(uni.getStorageSync('address') || '{}'),
    token:uni.getStorageSync('token') || '',
    userInfo:JSON.parse(uni.getStorageSync('userInfo') || '{}'),
    // 重定向
    redirect: null
  }),
  mutations: {
    //更新收货地址
    updateAddress(state,address) {
      state.address = address
    },
    // 持久化存储地址
    storageAddress(state,ad) {
      uni.setStorageSync('address',JSON.stringify(ad))
    },
    // 更新用户信息
    updateUserInfo(state,newUserInfo) {
      state.userInfo = newUserInfo
      this.commit('m_user/userInfoStorage')
    },
    // 持久化存储到本地
    userInfoStorage(state) {
      uni.setStorageSync('userInfo',JSON.stringify(state.userInfo))
    },
    // 更新token
    updateToken(state,token) {
      state.token = token
      this.commit('m_user/tokenSTorage')
    },
    // 持久化存储token
    tokenSTorage(state) {
      uni.setStorageSync('token',JSON.stringify(state.token))
    },
    updateReairect(state,info) {
      state.redirect = info
    }
  },
  getters: {
    ad(state) {
      if(JSON.stringify(state.address) === '{}') {
        return ''
      }
      return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
  
}